//
//  lotCloud.m
//  多云
//
//  Created by rimi on 16/3/22.
//  Copyright © 2016年 com.ruifeng. All rights reserved.
//

#import "LotCloud.h"

@implementation LotCloud
- (SunView *)sun{
    if (!_sun) {
        _sun = [[SunView alloc]initWithFrame:CGRectMake(self.bounds.size.width*0.1, self.bounds.size.height*0.1, self.bounds.size.width*0.84, self.bounds.size.height*0.54)];
 
    }
    return _sun;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:_sun];
        [self viewDidLoad];
        
    }
    return self;
}
- (void)viewDidLoad{
    SunView *sun1 = [[SunView alloc]initWithFrame:CGRectMake(self.bounds.size.width*0.25,self.bounds.size.height*0.08 , self.bounds.size.width*0.5, self.bounds.size.height*0.5)];
    sun1.speed = 40;
    [self addSubview:sun1];
    UIImageView *cloud = [[UIImageView alloc]initWithFrame:CGRectMake(self.bounds.size.width*0.05, self.bounds.size.width*0.25, self.bounds.size.width*0.84, self.bounds.size.height*0.54)];
    cloud.image = [UIImage imageNamed:@"云"];
    [self addSubview:cloud];

    [UIView animateWithDuration:3 animations:^{
        cloud.frame  = CGRectMake(self.bounds.size.width*0.05, self.bounds.size.width*0.25, self.bounds.size.width*0.84, self.bounds.size.width*0.54);
    } completion:^(BOOL finished){
        CAKeyframeAnimation * keyframe = [CAKeyframeAnimation animationWithKeyPath:@"position.x"];
        keyframe.repeatCount = HUGE_VAL;
        keyframe.values = @[@(self.bounds.size.width*0.41),@(self.bounds.size.width*0.57),@(self.bounds.size.width*0.41)];
        keyframe.duration = 18;
        [cloud.layer addAnimation:keyframe forKey:nil];
    }];

   
}

//控件消失响应动画
- (void)disMiss{
    [UIView animateWithDuration:0.5 animations:^{
        self.transform = CGAffineTransformMakeScale(0.1, 0.1);
        self.alpha = 0;
    } completion:^(BOOL finished){
        [self removeFromSuperview];
    }];
}

@end
